﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Nox.Amuse.Helpers;

namespace Nox.Amuse.Model
{
    [XmlRoot("Update")]
    public class Update
    {
        public int NewMajorVersionNumber { get; set; }

        public int NewMinorVersionNumber { get; set; }

        public int NewBuildVersionNumber { get; set; }

        public int NewRevisionVersionNumber { get; set; }

        [XmlIgnore]
        public Version NewVersion
        {
            get
            {
                return new Version(NewMajorVersionNumber,
                    NewMinorVersionNumber,
                    NewBuildVersionNumber,
                    NewRevisionVersionNumber);
            }
        }

        public string Details { get; set; }

        public int EstimatedTotalDownloadSizeInBytes { get; set; }

        public string DotNetFrameWorkVersionRequired { get; set; }

        /// <summary>
        /// Attempts to Load settings from the disk and push them in to a new instance. If file is not found, returns null;
        /// </summary>
        /// <returns>A new settings model</returns>
        public static Update Load(string fileName)
        {
            Update u = null;
            var serializer = new XmlSerializer(typeof(Update));
            var textReader = FileHelper.StartReadingTextFileFromFullPath(FileHelper.GetApplicationDataFolderPath() + fileName);
            if (textReader != null)
            {
                try
                {
                    u = (Update)serializer.Deserialize(textReader);
                }
                catch
                { }
                finally
                {
                    textReader.Close();
                }
            }
            return u;
        }

    }
}
